package com.dingwei.lesyndrome.mvp.presenter;

import android.text.TextUtils;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.MyNewsBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class AddAddressPresenter extends basePresenter {

    private Contract.AddAddressView addAddressView;

    public AddAddressPresenter(Contract.AddAddressView view) {
        super(view);
        this.addAddressView = view;
    }

    public void addAddress(String id, String name, String current_cor) {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.ADDRESS_SAVE);
        if (!TextUtils.isEmpty(id)) {
            rp.addBodyParameter("id", id);
        }
        rp.addBodyParameter("name", name);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("longitude", current_cor.split(",")[0]);
        rp.addBodyParameter("latitude", current_cor.split(",")[1]);
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                showToast(baseBean.message);
                addAddressView.addSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
